<?php
include dirname(dirname(dirname(__FILE__)))."/s_user-manage/s_user-verify.php";
include dirname(dirname(dirname(dirname(__FILE__))))."/admin/goods-manage/functions.php";
$uploaddir = dirname(dirname(dirname(__FILE__))).'/production-accessory/'.$_SESSION['s_username'].'/';//设置文件保存目录 注意包含/
$type=array("rar","zip");//设置允许上传文件的类型
$res["error"] ="";//错误信息
$res["msg"] ="";//提示信息
if (!file_exists($uploaddir)){
	mkdir($uploaddir,0777,true);
	
}
if (!empty($_FILES)) {
	
	$a=strtolower(fileext($_FILES['accessory']['name']));
	//判断文件类型
	if(!in_array(strtolower(fileext($_FILES['accessory']['name'])),$type))
	{
	$res["error"] = "文件类型错误";
	}else{
		$filename=explode(".",$_FILES['accessory']['name']);
		do{
				$filename[0]=random(10); //设置随机数长度
				$name=implode(".",$filename);
				$uploadfile=$uploaddir.$name;
			}while(file_exists($uploadfile));
		if (move_uploaded_file($_FILES['accessory']['tmp_name'],$uploadfile)){
			
			$res["msg"] = "ok";
			$res["storeName"]=$name;
		}else{
			$res["error"] = "上传失败";
			
			}
	}
}
echo json_encode($res);
?>